﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
namespace DataLibrary
{
    public class Ctbl_Khachhang:IData<tbl_Khachhang>
    {
        public Ctbl_Khachhang(String myconnecString) : base(myconnecString) { }

        public override List<tbl_Khachhang> GetAll(tbl_Khachhang item)
        {
            throw new NotImplementedException();
        }

        public override tbl_Khachhang GetItemById(object id)
        {
            return GetAll().SingleOrDefault(p => p.IdKhachhang == Convert.ToInt32(id));
        }

        public override tbl_Khachhang GetItem(IDataReader dr)
        {
            tbl_Khachhang obj = new tbl_Khachhang();
            obj.IdGroup = Convert.ToInt32(dr[tbl_Khachhang.c_idGroup]);
            obj.IdKhachhang = Convert.ToInt32(dr[tbl_Khachhang.c_idKhachhang]);
            obj.NameKhachhang = Convert.ToString(dr[tbl_Khachhang.c_nameKhachhang]);
            return obj;
        }

        public override List<tbl_Khachhang> GetAll()
        {
            String strSQL = "select * from "+ tbl_Khachhang.b_tbl_Khachhang;
            return GetAll(strSQL, CommandType.Text);
        }

        protected override int InsertOnSubmit(tbl_Khachhang item, int t)
        {
            int id = -1;
            String strProName = "ProKhachHang";
            id=connec.ExecuteNonQuery(strProName,CommandType.StoredProcedure,new SqlParameter("@flag",t),
                new SqlParameter("@"+tbl_Khachhang.c_idGroup,item.IdGroup),new SqlParameter("@"+tbl_Khachhang.c_idKhachhang,item.IdKhachhang),
                new SqlParameter("@"+tbl_Khachhang.c_nameKhachhang,item.NameKhachhang));
            return id;
        }
    }
}
